#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct
{
    char name[10];
    int age;
} Student_t, *Student_p;

typedef struct
{
    Student_p stu;    // 数组
    int max_size;     // 学生最大容量
    int size;         // 学生索引
    int extend_ratio; // 扩容倍数
} MyList_t, *MyList_p;

MyList_p StuList_create()
{
    MyList_p StuList = (MyList_p)malloc(sizeof(MyList_t));
    StuList->max_size = 5;
    StuList->size = 0;
    StuList->extend_ratio = 2;
    StuList->stu = (Student_p)malloc(sizeof(Student_t) * StuList->max_size);
    return StuList;
}

void expand(MyList_p mylist)
{
    mylist->max_size *= mylist->extend_ratio;
    Student_p newStu = (Student_p)calloc(mylist->max_size, sizeof(Student_t)); // 个数 大小
    for (int i = 0; i < mylist->max_size; i++)
    {
        if (i < mylist->size)
        {
            newStu[i] = mylist->stu[i];
        }
    }
    free(mylist->stu);
    mylist->stu = newStu;
}

void push(MyList_p mylist, char *name, int age)
{
    if (mylist->size >= mylist->max_size)
    {
        expand(mylist);
    }
    mylist->stu[mylist->size].age = age;
    strcpy(mylist->stu[mylist->size].name, name);
    mylist->size++;
}

void print_student(MyList_p mylist)
{
    for (int i = 0; i < mylist->size; i++)
    {
        printf("%s %d\n", mylist->stu[i].name, mylist->stu[i].age);
    }
}

int main()
{
    MyList_p StuList = StuList_create();
    push(StuList, "zhangsan", 18);
    push(StuList, "lisi", 19);
    push(StuList, "wangwu", 20);
    push(StuList, "zhaoliu", 21);
    push(StuList, "qianshi", 22);
    push(StuList, "sunba", 23);
    push(StuList, "zhoujiu", 24);
    push(StuList, "zhengshi", 25);
    push(StuList, "wugong", 26);
    push(StuList, "liujiu", 27);
    push(StuList, "sunqi", 28);
    print_student(StuList);
    return 0;
}